'''
Description: 
Autor: didiplus
Date: 2023-01-13 10:22:40
LastEditors: lin
LastEditTime: 2023-01-13 10:31:34
'''

import cnblogs_spider
import threading
from loguru import logger
import time

def single_thread():
    logger.info("single_thread begin")
    for url in cnblogs_spider.urls:
        cnblogs_spider.craw(url)
    logger.info("single_thread end")



def multi_thread():
    logger.info("single_thread begin")
    threads = []

    for url in cnblogs_spider.urls:
        threads.append(
            threading.Thread(target=cnblogs_spider.craw,args=(url,))
        )
    
    for task in threads:
        task.start()
    
    for task in threads:
        task.join()
    logger.info("single_thread end")

if __name__ == "__main__":
    start = time.time()
    single_thread()
    end = time.time()
    logger.info("single thread cost: {}".format(end-start))
    start = time.time()
    multi_thread()
    end = time.time()
    logger.info("multi thread cost: {}".format(end-start))